package algo.stack.impl;

import com.fay.algo.linkedlist.impl.LinkedList;

/**
 * @Title:
 * @Description:
 * @Author Fay Wang
 * @Date 2022/4/27 10:17
 * @Version 1.0
 */
public class LinkedListBasedStack<E> implements Stack<E> {

    private LinkedList<E> list;

    public LinkedListBasedStack() {
        list = new LinkedList<>();
    }

    @Override
    public int getSize() {
        return list.getSize();
    }

    @Override
    public boolean isEmpty() {
        return list.isEmpty();
    }

    @Override
    public void push(E e) {
        list.addFirst(e);
    }

    @Override
    public E pop() {
        return list.removeFirst();
    }

    @Override
    public E peek() {
        return list.getFirst();
    }

    @Override
    public String toString() {
        StringBuilder res = new StringBuilder();
        res.append("Stack:top");
        res.append(list);
        return res.toString();
    }
}
